package com.example.spring.boot.spring.json;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

public class JsonUtils {

    public static String  toString(Object obj ){
        String result = null;
        try {
            ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
            result = objectMapper.writeValueAsString(obj);
        }catch (Exception e){
            result = obj == null? "null":obj.toString();
        }
        return result;
    }
}
